package com.cetc.common.validate;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2018/9/26.
 */
public class MoneyTypeValidator implements ConstraintValidator<MoneyType, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(null == value || value.equals("")){
            return true;
        }

        // 判断小数点后2位的数字的正则表达式
        Pattern pattern=Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$");
        Matcher match=pattern.matcher(value);
        if(match.matches()==false){
            return false;
        }
        else {
            return true;
        }
    }

}
